通过ARMS Go探针和ASM对Go应用进行全链路灰度并实时监控

本文介绍如何通过ARMS Go探针和ASMGo应用进行全链路灰度并实时监控。

Demo应用

Demo应用部署架构:

image

Demo应用YAML:

说明

所有应用均部署在go-gray命名空间下。

  • 入口应用

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: requestsender
      namespace: go-gray
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: requestsender
      template:
        metadata:
          labels:
            app: requestsender
            ASM_TRAFFIC_TAG: v1
            version: v1
            armsPilotCreateAppName: requestsender
            armsPilotAutoEnable: 'on'
            aliyun.com/app-language: golang
        spec:
          containers:
            - name: requestsender
              image: registry.cn-hangzhou.aliyuncs.com/private-mesh/hellob:requestsender-demo
              imagePullPolicy: Always
              ports:
                - containerPort: 8080
    
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: requestsender
      namespace: go-gray
    spec:
      selector:
        app: requestsender
      ports:
        - protocol: TCP
          port: 80
          targetPort: 8080
      type: ClusterIP
  • 应用A

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: go-demo-a-base
      namespace: go-gray
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: go-demo-a
      template:
        metadata:
          labels:
            app: go-demo-a
            armsPilotAutoEnable: "on"
            ASM_TRAFFIC_TAG: v1
            version: v1
            armsPilotCreateAppName: "go-demo-a"
            aliyun.com/app-language: golang
        spec:
          containers:
            - name: go-demo-a
              image: registry.cn-hangzhou.aliyuncs.com/private-mesh/hellob:a-demo
              imagePullPolicy: Always
              ports:
                - containerPort: 8080
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: go-demo-a-gray
      namespace: go-gray
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: go-demo-a
      template:
        metadata:
          labels:
            app: go-demo-a
            ASM_TRAFFIC_TAG: v2
            version: v2
            armsPilotCreateAppName: go-demo-a
            armsPilotAutoEnable: 'on'
            aliyun.com/app-language: golang
        spec:
          containers:
            - name: go-demo-a-base
              image: registry.cn-hangzhou.aliyuncs.com/private-mesh/hellob:a-demo-gray
              imagePullPolicy: Always
              ports:
                - containerPort: 8080
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: go-demo-a
      namespace: go-gray
    spec:
      selector:
        app: go-demo-a
      ports:
        - protocol: TCP
          port: 80
          targetPort: 8080
      type: ClusterIP
  • 应用B

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: go-demo-b-base
      namespace: go-gray
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: go-demo-b
      template:
        metadata:
          labels:
            app: go-demo-b
            ASM_TRAFFIC_TAG: v1
            version: v1
            armsPilotCreateAppName: go-demo-b
            armsPilotAutoEnable: 'on'
            aliyun.com/app-language: golang
        spec:
          containers:
            - name: go-demo-b
              image: registry.cn-hangzhou.aliyuncs.com/private-mesh/hellob:b-demo
              imagePullPolicy: Always
              ports:
                - containerPort: 8080
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: go-demo-b-gray
      namespace: go-gray
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: go-demo-b
      template:
        metadata:
          labels:
            app: go-demo-b
            ASM_TRAFFIC_TAG: v2
            version: v2
            armsPilotCreateAppName: go-demo-b
            armsPilotAutoEnable: 'on'
            aliyun.com/app-language: golang
        spec:
          containers:
            - name: go-demo-b
              image: registry.cn-hangzhou.aliyuncs.com/private-mesh/hellob:b-demo-gray
              imagePullPolicy: Always
              ports:
                - containerPort: 8080
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: go-demo-b
      namespace: go-gray
    spec:
      selector:
        app: go-demo-b
      ports:
        - protocol: TCP
          port: 80
          targetPort: 8080
      type: ClusterIP
  • 应用C

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: go-demo-c-base
      namespace: go-gray
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: go-demo-c
      template:
        metadata:
          labels:
            app: go-demo-c
            ASM_TRAFFIC_TAG: v1
            version: v1
            armsPilotCreateAppName: go-demo-c
            armsPilotAutoEnable: 'on'
            aliyun.com/app-language: golang
        spec:
          containers:
            - name: go-demo-c
              image: registry.cn-hangzhou.aliyuncs.com/private-mesh/hellob:c-demo
              imagePullPolicy: Always
              ports:
                - containerPort: 8080
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: go-demo-c-gray
      namespace: go-gray
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: go-demo-c
      template:
        metadata:
          labels:
            app: go-demo-c
            ASM_TRAFFIC_TAG: v2
            version: v2
            armsPilotCreateAppName: go-demo-c
            armsPilotAutoEnable: 'on'
            aliyun.com/app-language: golang
        spec:
          containers:
            - name: go-demo-c
              image: registry.cn-hangzhou.aliyuncs.com/private-mesh/hellob:c-demo-gray
              imagePullPolicy: Always
              ports:
                - containerPort: 8080
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: go-demo-c
      namespace: go-gray
    spec:
      selector:
        app: go-demo-c
      ports:
        - protocol: TCP
          port: 80
          targetPort: 8080
      type: ClusterIP

使用ARMS监控Golang应用

通过Golang探针将Go应用接入ARMS应用监控,即可在ARMS中查看对应应用的应用拓扑、接口调用、数据库分析等相关监控数据。

使用ASM进行全链路灰度

  1. 创建ASM实例并添加集群。

  2. 创建入口网关

  3. 使用以下内容创建命名空间为istio-systemingressgateway网关规则。具体操作,请参见创建ingressgateway网关规则

    展开查看网关规则YAML示例

    apiVersion: networking.istio.io/v1beta1
    kind: Gateway
    metadata:
      name: ingressgateway
      namespace: istio-system
    spec:
      selector:
        istio: ingressgateway
      servers:
        - port:
            number: 80
            name: http
            protocol: HTTP
          hosts:
            - '*'
  4. Demo的所有应用注入Sidecar并重启。具体操作,请参见安装Sidecar代理

  5. 配置链路追踪。

    1. 创建opentelemetry-operator-system命名空间。

      kubectl create namespace opentelemetry-operator-system
    2. 创建链路追踪的Service。

      apiVersion: v1
      kind: Service
      metadata:
        name: default-collector
        namespace: opentelemetry-operator-system
      spec:
        ports:
          - port: 4317
            protocol: TCP
            targetPort: 4317
        selector:
          app: default-collector
        sessionAffinity: None
        type: ClusterIP
      
    3. ASM控制台开启链路追踪。

      • OpenTelemetry服务域名(完整FQDN):default-collector.opentelemetry-operator-system.svc.cluster.local

      • OpenTelemetry服务端口:4317

      image

    4. 可观测配置页面的链路追踪设置区域,启用链路追踪,并按需配置采样率。

      image

  6. 创建泳道

    1. 创建泳道组test

      配置项

      说明

      trace id请求头

      traceparent

      引流请求头

      x-asm-prefer-tag

      泳道服务

      requestsendergo-demo-ago-demo-bgo-demo-c

      image

    2. 创建v1v2泳道。

      配置项

      说明

      泳道名称

      分别配置为v1v2

      配置服务标签

      标签名称:选择ASM_TRAFFIC_TAG

      标签值:分别选择v1v2

      添加服务

      v1泳道:选择requestsendergo-demo-ago-demo-bgo-demo-c

      v2泳道:选择go-demo-ago-demo-c

    3. 分别为v1v2泳道添加引流规则。

      配置项

      说明

      入口服务

      选择requestsender.go-gray.svc.cluster.local

      引流规则

      名称:分别输入v1v2

      域名*

      匹配方式精确

      匹配内容/greetinit

      创建完成示例:

      image

验证结果

  1. ASM网关 > 入口网关页面获取ASM网关的公网IP。

  2. 执行以下命令,设置环境变量。

    xxx.xxx.xxx.xxx为上一步获取的IP。

    export ASM_GATEWAY_IP=xxx.xxx.xxx.xxx
  3. 验证全链路灰度功能是否生效。

    • 基线:

      for i in {1..100};  do curl   -H 'x-asm-prefer-tag: v1' http://${ASM_GATEWAY_IP}/greetinit;  echo ''; sleep 1; done;

      预期输出:

      {"code":0,"data":{"greeting":"Hello ","callChain":"Init:base:172.30.208.29 - A:base:172.30.208.114 - B:base:172.30.208.116 - C:base:172.30.208.120"},"message":"success"}
      {"code":0,"data":{"greeting":"Hello ","callChain":"Init:base:172.30.208.29 - A:base:172.30.208.114 - B:base:172.30.208.116 - C:base:172.30.208.120"},"message":"success"}
    • 灰度:

      for i in {1..100};  do curl   -H 'x-asm-prefer-tag: v2' http://${ASM_GATEWAY_IP}/greetinit;  echo ''; sleep 1; done;

      预期输出:

      {"code":0,"data":{"greeting":"Hello ","callChain":"Init:base:172.30.208.29 - A:gray:172.30.208.115 - B:base:172.30.208.116 - C:gray:172.30.208.122"},"message":"success"}
      {"code":0,"data":{"greeting":"Hello ","callChain":"Init:base:172.30.208.29 - A:gray:172.30.208.115 - B:base:172.30.208.116 - C:gray:172.30.208.122"},"message":"success"}

查看监控数据

ARMS控制台应用监控 > 应用列表页面查看对应的Go应用监控。

image